package me.wangqu.weiyouqu.web.rest;

import com.google.gson.JsonObject;
import me.wangqu.weiyouqu.web.rest.business.model.BaseModel;
import me.wangqu.weiyouqu.web.rest.business.service.JpushService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by joln on 2016/7/25.
 */
@RestController
@RequestMapping("/api")
public class JpushResource {
    private final Logger log = LoggerFactory.getLogger(JpushResource.class);

    private static final String appKey = "288a447102d4fec421de4f95";

    private static final String masterSecret = "1d5901b9072523be9a140242";

    private Jpush jpush;

    @Autowired
    private JpushService jpushService;


    @RequestMapping(value = "/jpush",
            method = RequestMethod.GET)
    public void setJpush(Integer id) {
        BaseModel jpushData = jpushService.setJpush(id);
        JsonObject object = new JsonObject();
        object.addProperty("title", jpushData.getTitle());
        object.addProperty("imgURL", jpushData.getImg_arr());
        object.addProperty("link", jpushData.getUrl());
        Jpush.testSendPush(appKey, masterSecret, object.toString(), jpushData.getTitle());
        log.debug("极光推送");
    }

}
